package com.study.leetcode;

public class Solution_387 {
    public int firstUniqChar(String s) {
        int[] counter = new int[26];
        int len = s.length();
        for (int i = 0; i < len; i++) {
            counter[s.charAt(i) - 'a']++;
        }
        int minIndex = Integer.MAX_VALUE;
        for (int i = 0; i < counter.length; i++) {
            int indexOf = s.indexOf((char) (i + 'a'));
            if (counter[i] == 1 && indexOf < minIndex) {
                minIndex = indexOf;
            }
        }
        return minIndex != Integer.MAX_VALUE ? minIndex : -1;
    }

}
